<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('婚庆公司管理')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            公司名称：<input type="text" name="companyName"/>
                        </li>
                        <li>
                            账号状态：
                            <select name="companyState" th:with="type=${@dict.getType('sys_normal_disable')}">
                                <option value="-1">请选择</option>
                                <option value="1">正常</option>
                                <option value="2">禁用</option>
                            </select>
                        </li>
                        <!--<li>
                            订单量排序：
                            <select name="hostOrderNum" th:with="type=${@dict.getType('sys_normal_disable')}">
                                <option value="-1">请选择</option>
                                <option value="1">订单量降序</option>
                                <option value="2">订单量升序</option>
                            </select>
                        </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="user:company:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="user:company:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="user:company:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="user:company:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('user:host:edit')}]];
    var removeFlag = [[${@permission.hasPermi('user:host:remove')}]];
    var disableFlag = [[${@permission.hasPermi('user:host:state')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "user/company";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "companyId",
            modalName: "婚庆公司",
            sortOrder: "asc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'companyId',
                    title: '编号'
                },
                {
                    field: 'companyName',
                    title: '公司名称',
                },
                {
                    field: 'companyBoss',
                    title: '法人：手机号'
                },
                {
                    field: 'companyEmail',
                    title: '邮箱'
                },
                {
                    field: 'companyDate',
                    title: '开通时间',
                    sortable: true
                },
                {
                    field: 'hostPrice',
                    title: '订单量',
                },
                {
                    field: 'companyState',
                    title: '账号状态',
                    formatter: function (value, row, index) {
                        if (value == 2) {
                            return "<span style='color:red;'>禁用</span>";
                        }else if (value == 0){
                            return "<span style='color:pink;'>未审核</span>";
                        }
                        return "正常";
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showPlanner('+row.companyId+')">策划师列表</a> ');
                        if (row.companyState == 2) {
                            actions.push('<a class="btn btn-info btn-xs ' + disableFlag + '" href="javascript:void(0)" onclick="updateState(this,' + row.companyId + ',' + row.companyState + ')">恢复账号</a>');

                        } else if (row.companyState == 0) {
                            actions.push('<a class="btn btn-info btn-xs ' + disableFlag + '" href="javascript:void(0)" onclick="updateState(this,' + row.companyId + ',' + row.companyState + ')">审核账号</a>');
                        } else {
                            actions.push('<a class="btn btn-danger btn-xs ' + disableFlag + '" href="javascript:void(0)" onclick="updateState(this,' + row.companyId + ',' + row.companyState + ')">禁用账号</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });



    // 修改状态，禁用和启用
    function updateState(obj, companyId, companyState) {
        if (companyState == 2) {
            $.modal.confirm("您是否确定恢复该账号",function () {
                companyState = 1;
                $.post(prefix + "/updateState", {"companyId": companyId, "companyState": companyState}, function (data) {
                    if (data.code == 0) {
                        $.table.refresh();
                    } else {
                        $.modal.msgSuccess("操作失败");
                    }
                }, "json");
            })
        } else  if(companyState == 0) {
            $.modal.confirm("您是否确定审核该账号",function () {
                companyState = 1;
                $.post(prefix + "/updateState", {"companyId": companyId, "companyState": companyState}, function (data) {
                    if (data.code == 0) {
                        $.table.refresh();
                    } else {
                        $.modal.msgSuccess("操作失败");
                    }
                }, "json");
            })
        } else {
            $.modal.confirm("您是否确定禁用该账号",function () {
                companyState = 2;
                $.post(prefix + "/updateState", {"companyId": companyId, "companyState": companyState}, function (data) {
                    if (data.code == 0) {
                        $.table.refresh();
                    } else {
                        $.modal.msgSuccess("操作失败");
                    }
                }, "json");
            })
        }
    }

    //展示策划师列表
    function showPlanner(companyId) {
        $.modal.openTab('策划师列表', prefix + "/planner/"+companyId);
    }
</script>
</body>
</html>